package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"删除用户","删除");
        System.out.println(userInfo);
        try (
                Connection connection = DBUtil.getConnection();
        ) {
            Statement Statement = connection.createStatement();
            String sql = "DELETE FROM userinfo\n " +
                    "WHERE username= '"+userInfo.getUsername()+"'";
            System.out.println(sql);
            int num = Statement.executeUpdate(sql);
            if (num > 0) {
                System.out.println("删除数据成功");
            } else {
                System.out.println("删除数据失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}

